package nl.haemers.buttons
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import nl.haemers.base.BaseSprite;
	import nl.haemers.buttons.IBaseButton;
	/**
	 * @author Jonathan Haemers
	  */
	public class BaseButton extends BaseSprite implements IBaseButton
	{
		protected var _enabled 					:Boolean;
				
		public function BaseButton() 
		{
			_enabled = true;
			super();
		}
		
		/** Public methods **/
		
		/** Getters & Setters **/
		public function get enabled() : Boolean
		{ 
			return _enabled;
		}
		public function set enabled( value:Boolean ) : void 
		{
			_enabled = value;
			if (stage)
			{
				configButton();
				configListeners();
			}
		}
		
		/** Protected methods **/
		override protected function init( e:Event = null ) : void
		{
			super.init(e);
			
			startup();
		}
		
		protected function startup() : void
		{
			hitArea = new BaseSprite();
			
			createHitArea();
			configButton();
			configListeners();
		}
		
		protected function configButton() : void
		{
			hitArea.buttonMode = _enabled;
			hitArea.useHandCursor = _enabled;
		}
		
		protected function configListeners() : void
		{
			if (_enabled)
			{
				hitArea.addEventListener(MouseEvent.CLICK, clickHandler);
				hitArea.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
				hitArea.addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
			}
		}
		
		/** Abstract Methods **/
		/** Public methods **/
		public function show() : void
		{
		}
		
		public function hide() : void
		{
		}
		
		/** Protected methods **/
		protected function createHitArea() : void
		{
		}
		
		protected function clickHandler(e:MouseEvent) : void
		{
		}
		
		protected function rollOverHandler(e:MouseEvent) : void
		{
		}
		
		protected function rollOutHandler(e:MouseEvent) : void
		{
		}
	}

}